import { copyFileSync, mkdirSync, existsSync } from 'fs'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

const rootDir = join(__dirname, '..')
const distDir = join(rootDir, 'dist')

// 确保 dist 目录存在
if (!existsSync(distDir)) {
  mkdirSync(distDir, { recursive: true })
}

// 复制 manifest.json
const manifestSrc = join(rootDir, 'public', 'manifest.json')
const manifestDest = join(distDir, 'manifest.json')
copyFileSync(manifestSrc, manifestDest)

console.log('✅ manifest.json 已复制到 dist 目录')

// 复制 PNG 图标
const iconsDir = join(distDir, 'icons')
if (!existsSync(iconsDir)) {
  mkdirSync(iconsDir, { recursive: true })
}

const iconSizes = [16, 48, 128]
for (const size of iconSizes) {
  const iconSrc = join(rootDir, 'public', 'icons', `icon-${size}.png`)
  const iconDest = join(iconsDir, `icon-${size}.png`)
  copyFileSync(iconSrc, iconDest)
  console.log(`✅ icon-${size}.png 已复制到 dist 目录`)
}

